import axios from 'axios'
import DataUtil from '../common/dataUtil'
 
export const baseURL = 'http://192.168.0.8:9080'; 
axios.defaults.baseURL = baseURL;
axios.defaults.timeout =  5000;
var parMount = '';
var reg = {};
var regSbustr = {};
var regSbustrToKey = {};
var regObj = {};
var regJSONObj = '';
var regSbustrToKeyForm = '';
var fast;
var fanl;
var rightStr;
var leftStr;
///////加密随机数
const sa = DataUtil.uuids();
///////加密消息签名
const si = '';

/////////公共参数
const headers = {
  't': DataUtil.t(),///////时间戳
  "ch": "APP_PC_1",////渠道号
  "sa": sa,//加密盐，客户端指定
  "si": si,//加密盐，客户端指定
  "pv": "W1.0",
  'token': 'BEWR1J3I5fQwv8cgQppb8jqCWeMOziFN',
};
//添加请求拦截器  
axios.interceptors.request.use(function (config) {
    
    /////参数合并
    // for (var key in config.data) {
    // if (config.data.hasOwnProperty(key) === true) {
    //     headers[key] = config.data[key];
    // }
    // }
    // regObj = config.data;
    // config.data = regObj;/////////请求传参body
    // // 抽离出condition
    // for (var key in regObj.body) {
    // if (key == 'condition' || key == 'recharges') {
    //     parMount = { 'condition': regObj.body[key] };
    //     regSbustrToKey[key] = parMount[key];
    //     // console.log(parMount);
    // }
    // }
    // /////抽离出condition外参数
    // for (var key in regObj.body) {
    // if (key !== 'condition' || key !== 'recharges') {
    //     reg[key] = regObj.body[key];
    //     regSbustrToKey[key] = reg[key];
    //     // console.log(reg);
    // }
    // }
    // /////抽离出body外参数
    // for (var key in headers) {
    // if (key !== 'body') {
    //     regSbustr[key] = headers[key];
    //     regSbustrToKey[key] = regSbustr[key];
    //     // console.log(regSbustr);
    // }
    // }
    // regJSONObj = JSON.stringify(regSbustrToKey).replace(/(^\{*)|(}"*$)/g, "").split(',');
    // //参数格式化合并为字符串
    // for (let i = 0; i < regJSONObj.length; i++) {
    // fast = regJSONObj[i].replace(/\"/g, "");
    // regSbustrToKeyForm += fast.substring(0, fast.indexOf(':')) + '=' + fast.substring(fast.indexOf(':') + 1) + '&';
    // regSbustrToKeyForm.replace(/(&"*$)/g, "");
    // }
    // leftStr = regSbustrToKeyForm.substring(0, regSbustrToKeyForm.indexOf('condition'));
    // rightStr = regSbustrToKeyForm.substring(regSbustrToKeyForm.indexOf('}') + 1);
    // regSbustrToKeyForm = regSbustrToKeyForm.substring(regSbustrToKeyForm.indexOf('{') + 1, regSbustrToKeyForm.indexOf('}'));
    // let regSbustrToKeyFormStr = regSbustrToKeyForm.replace(/\=/g, ":").replace(/\&/g, ",").split(',');
    // for (let i = 0; i < regSbustrToKeyFormStr.length; i++) {
    // regSbustrToKeyFormStr[i] = '"' + regSbustrToKeyFormStr[i].substring(0, regSbustrToKeyFormStr[i].indexOf(':')) + '":"' + regSbustrToKeyFormStr[i].substring(regSbustrToKeyFormStr[i].indexOf(':') + 1) + '"';
    // }
    // fanl = (leftStr + 'condition={' + regSbustrToKeyFormStr.join(',') + '}' + rightStr.substring(rightStr.indexOf('}') + 1)).replace(/(&"*$)/g, "").split('&').sort().join('&');
    // headers.si = md5(md5(fanl + '&key=q1npCXKVuefsR2Z2DTqOZAN7') + '&' + DataUtil.signature());
    // //////////设置请求headers
    // config.headers.common['t'] = DataUtil.t();
    // config.headers.common['ch'] = 'APP_PC_1';
    // config.headers.common['sa'] = sa;
    // config.headers.common['si'] = headers.si;
    // config.headers.common['token'] = 'BEWR1J3I5fQwv8cgQppb8jqCWeMOziFN';
    config.headers['Authorization'] = DataUtil.sid();
    
    return config
}, function (error) {
    return Promise.reject(error);
})

//////////////////////////////////登录//////////////////////////////////
export const login = params =>{
    return axios.post('/system/login.action',params).then(res => res.data)
}


//获取菜单
export const getRoutes = params =>{
    return axios.post('/system/getUserMenus.action',params).then(res => res.data)
}
//获取菜单选项
export const getMenusList = params =>{
    return axios.post('/system/getResourceTree.action',params).then(res => res.data)
}
//添加用户
export const addUser = params =>{
    return axios.post('/system/addUser.action',params).then(res => res.data)
}
//获取用户列表
export const getUserList = params =>{
    return axios.post('/system/getUserDataTable.action',params).then(res => res.data)
}
//获取用户角色权限选项
export const getUserRoleList = params =>{
    return axios.post('/system/getRoleList.action',params).then(res => res.data)
}

//获取用户详情
export const getUserDetails = params =>{
    return axios.post('/system/getUser.action',params).then(res => res.data)
}
//删除用户
export const deleteUser = params =>{
    return axios.post('/system/deleteUser.action',params).then(res => res.data)
}
//用户退出
export const logout = params =>{
    return axios.post('/system/logout.action',params).then(res => res.data)
}
//修改密码
export const updatePassword = params =>{ 
    return axios.post('/system/updatePassword.action',params).then(res => res.data)
}

//获取用户信息
export const getUserAndRoles = params =>{ 
    return axios.post('/system/getUserAndRoles.action',params).then(res => res.data)
}


//编辑用户信息
export const editedUser = params =>{ 
    return axios.post('/system/updateUser.action',params).then(res => res.data)
}
//添加角色
export const addRole = params =>{ 
    return axios.post('/system/addRole.action',params).then(res => res.data)
}
//获取角色列表
export const getRoleList = params =>{
    return axios.post('/system/getRoleDataTable.action',params).then(res => res.data)
}
//角色删除
export const deleteRole = params =>{
    return axios.post('/system/deleteRole.action',params).then(res => res.data)
}
////获取编辑角色详情  
export const getRoleDetail = params =>{
    return axios.post('/system/getRoleDetail.action',params).then(res => res.data)
}

////编辑角色详情  
export const updateRole = params =>{
    return axios.post('/system/updateRole.action',params).then(res => res.data)
}

////添加分类地区  
export const addResourceArea = params =>{
    return axios.post('/resource/addResourceArea.action',params).then(res => res.data)
}

////分类地区列表  
export const getResourceAreaDataTable = params =>{
    return axios.post('/resource/getResourceAreaDataTable.action',params).then(res => res.data)
}

////分类地区详情
export const getResourceAreaDetail = params =>{
    return axios.post('/resource/getResourceAreaDetail.action',params).then(res => res.data)
}

////分类地区详情修改
export const editedArea = params =>{
    return axios.post('/resource/updateResourceArea.action',params).then(res => res.data)
}
////分类地区详情删除
export const deleteArea = params =>{
    return axios.post('/resource/deleteResourceArea.action',params).then(res => res.data)
}

////添加分类类型  
export const addResourceType = params =>{
    return axios.post('/resource/addResourceType.action',params).then(res => res.data)
}

////分类类型列表  
export const getResourceTypeDataTable = params =>{
    return axios.post('/resource/getResourceTypeDataTable.action',params).then(res => res.data)
}

// ////分类类型详情
export const getResourceTypeDetail = params =>{
    return axios.post('/resource/getResourceTypeDetail.action',params).then(res => res.data)
}

////分类类型详情修改
export const editedType = params =>{
    return axios.post('/resource/updateResourceType.action',params).then(res => res.data)
}
////分类类型详情删除
export const deleteType = params =>{
    return axios.post('/resource/deleteResourceType.action',params).then(res => res.data)
}

////创建资源信息
export const submitDetail = params =>{
    return axios.post('/resource/addResourceBaseInfo.action',params).then(res => res.data)
}   
////查询分类地区
export const getResourceAreas = params =>{
    return axios.post('/resource/getResourceAreas.action',params).then(res => res.data)
}   
////查询分类类型
export const getResourceTypes = params =>{
    return axios.post('/resource/getResourceTypes.action',params).then(res => res.data)
}   

////资源基本信息列表
export const getResourceBaseData = params =>{
    return axios.post('/resource/getResourceBaseDataTable.action',params).then(res => res.data)
}   

////资源基本信息详情
export const getResourceBaseDetail = params =>{
    return axios.post('/resource/getResourceBaseDetail.action',params).then(res => res.data)
}   
    
////删除基本信息详情
export const deleteResourceBase = params =>{
    return axios.post('/resource/deleteResourceBase.action',params).then(res => res.data)
}
////修改基本信息详情
export const resetResourceBase = params =>{
    return axios.post('/resource/updateResourceBaseInfo.action',params).then(res => res.data)
}  
////上传轮播图片信息
export const addBanner = params =>{
    return axios.post('/banner/addBanner.action',params).then(res => res.data)
}
////轮播图片信息列表
export const getBannerDataTable = params =>{
    return axios.post('/banner/getBannerDataTable.action ',params).then(res => res.data)
}
////轮播图片信息详情列表
export const getBannerDetail = params =>{
    return axios.post('/banner/getBannerDetail.action',params).then(res => res.data)
}
////删除轮播图片信息列表
export const deleteBanner = params =>{
    return axios.post('/banner/deleteBanner.action',params).then(res => res.data)
}
////修改轮播图片信息列表
export const updateBanner = params =>{
    return axios.post('/banner/updateBanner.action',params).then(res => res.data)
}

////上传图片
export const uploadBanner = baseURL + '/public/file/uploadFile'

/////////点击上传时获取obs配置
export const bucketConfig = {
       ak : "CNMOJHZGNXGBSML347TH",
       sk : "bPJp3FOCuTXLDcCm8SkIADs8IdWgE1GsKaGkMd15",///////*** Access Key ***
       bucketname : "llitc-re",///////Secret Key
       endpoint : "obs.cn-east-3.myhuaweicloud.com",//////server
       objectKey : "re-movies/"
}